<!DOCTYPE html>
<html xmlns:th="http://www.w3.org/1999/xhtml" xmlns:cms="http://thymeleafexamples">
<head th:include="include/head">

</head>
<style>
		.content-wrapper, .main-footer, .main-header{
			margin-left: 0;
		}
</style>
<body class="hold-transition sidebar-mini layout-fixed">
	<div class="wrapper">


		<div class="content-wrapper">
			<!-- Content Header (Page header) -->
			<section class="content-header">
				<div class="container-fluid">
					<div class="row mb-2">
						<div class="col-sm-6">
							<h1>项目管理</h1>
						</div>
						<div class="col-sm-6">
							<ol class="breadcrumb float-sm-right">
								<li class="breadcrumb-item"><a href="#">首页</a></li>
								<li class="breadcrumb-item active">项目管理</li>
							</ol>
						</div>
					</div>
				</div>
				<!-- /.container-fluid -->
			</section>

			<!-- Main content -->
			<section class="content">
				<div class="container-fluid">
					<div class="row">
						<div class="col-md-12">
							<div class="card">
								<div class="card-header">
									<h3 class="card-title">项目列表</h3>
                                	   <button type="button" class="btn btn-primary btn-sm" id="add" style="float: right">新增</button>
                                	   <button type="button" class="btn btn-primary btn-sm" id="back" style="float: right;margin-right: 5px">返回部门</button>
								</div>
								<div class="card-header">
									<form id="search-form2" class="navbar-form form-inline"  th:action="@{/project/list}" method="post">
										<input type="hidden" name="baseId" id="baseId" th:value="${baseId}" />
										<div class="form-group " >
											<label>状态:</label>
											<div class="col-sm-2" >
												<!--												0新增；1处理中；2挂起；3已完成-->
												<select  name="state" th:value="${state}" class="form-control">
													<option value=""  >全部</option>
													<option value="1" th:selected="${state==1}">启用</option>
													<option value="0" th:selected="${state==0}">禁用</option>

												</select>
											</div>
										</div>
										<div class="form-group " >
											<label>项目名称:</label>
											<div class="col-sm-4" >
												<input type="text" name="name" th:value="${name}" placeholder="项目名称" class="form-control">
											</div>
										</div>
										<div class="form-group " >
											<button type="button" id="serch"  style="font-size:0.5rem;" class="btn btn-primary pull-right">查询</button>
										</div>
									</form>

								</div>
								<!-- /.card-header -->
								<div class="card-body">
									<table class="table table-bordered">
										<thead>
											<tr>
<!-- 												<th style="width: 10px">#</th> -->
												<th>项目代码</th>
												<th>项目名称</th>
												<th>状态</th>
<!-- 												<th style="width: 150px;">移动</th> -->
												<th style="width: 250px">操作</th>
											</tr>
										</thead>
										<tbody>
											<tr th:each="bean : ${pageInfo.list}" th:attr="id=tr_+${bean.projectId}">
												<td th:text="${bean.projectCode}"></td>
												<td th:text="${bean.projectName}"></td>
<!--												<td th:text="${bean.projectState==0?'禁用':'启用'}"></td>-->
												<td th:id="'strs'+${bean.projectId}"  th:text="${bean.projectState}==1?'启用':'停用'"
													th:style="${bean.projectState}==1?'color:blue':'color:red'"
												></td>
<!-- 												<td> -->
<!-- 													<button type="button" class="btn btn-primary btn-sm sortUp" -->
<!-- 														th:attr="data-id=|${bean.userId}">上移</button> -->
<!-- 													<button type="button" class="btn btn-info btn-sm sortDown" -->
<!-- 														th:attr="data-id=|${bean.userId}">下移</button> -->
<!-- 												</td> -->
												<td>
<!-- 													<a th:href="'../project/list?projectId='+${bean.projectId}"class="btn btn-primary btn-sm">-->
<!-- 														<i class="fas fa-folder"></i>项目-->
<!-- 													</a>&nbsp;&nbsp;-->
													<a th:href="'add?id='+${bean.projectId}+'&baseId='+${baseId}" class="btn btn-info btn-sm">
													 	<i class="fas fa-pencil-alt"></i>编辑
													</a> &nbsp;&nbsp; 
<!--													<a href="javascript:;" th:attr="data-id=|${bean.projectId}" class="btn btn-danger btn-sm del">-->
<!--														<i class="fas fa-trash"></i>删除-->
<!--													</a>-->
													<a href="javascript:;" th:attr="data-id=|${bean.projectId}" class="btn btn-danger btn-sm del">
														<i class="fas fa-trash"></i>
														<span th:id="'str'+${bean.projectId}" th:if="${bean.projectState==0}">启用</span>
														<span th:id="'str'+${bean.projectId}" th:if="${bean.projectState==1}">停用</span>
													</a>
												</td>
											</tr>
										</tbody>
									</table>
								</div>
								<cms:page></cms:page>
							</div>

						</div>
					</div>
				</div>
			</section>
		</div>
	</div>
	<!-- ./wrapper -->
	<div th:include="include/foot"></div>
	<script>
		$("#hospitalId").change(function (){
			let v=$(this).val();
			let t= $(this).find("option:selected").text();
			console.log(v,t)
			if(v>0){
				$("#hospitalName").val(t);
			}
			$.ajax({url:'../doctor/departmentList',data:"hospitalId="+v,success:function (data){
					if(data.res){
						$("#dpId").empty();
						$("#dpId").append("<option value=''>请选择科室</option>");
						for(let i=0;i<data.list.length;i++){
							console.log(data.list[i])
							$("#dpId").append("<option value='"+data.list[i].id+"'>"+data.list[i].departmentName+"</option>");
						}

					}
				}})
		});
	  $("#serch").click(function() {
	       $("#search-form2").submit();
	   });
		$().ready(function() {
			$("#add").click(function() {
			 	let  id=	$('#baseId').val()
				location.href = 'add?baseId='+id;
			});
			$("#back").click(function() {
				location.href = '../base/list';
			});

			$(".del").click(function() {
				let id = $(this).data('id');
				var das=$("#str"+id).text();
				if (confirm('确定'+das+'项目吗？')) {
					$.ajax({
						url : 'del?id=' + id,
						success : function(e) {
							console.log(e)
							if (e.state==1) {
								$("#str"+id).text("启用");
								$("#strs"+id).empty();
								$("#strs"+id).append('<span style="color:red">停用</span>');
							}else{
								$("#str"+id).text("停用");
								$("#strs"+id).empty();
								$("#strs"+id).append('<span style="color:blue">启用</span>');
							}
						},error:function(e){
							layer.msg(e.responseText, {icon: 5});
						}
					});
				}

			});

			// $(".del").click(function() {
			// 	if (confirm('确定删除内容吗？')) {
			// 		let id = $(this).data('id');
			// 		$.ajax({
			// 			url : 'del?id=' + id,
			// 			success : function(e) {
			// 				if (e.res) {
			// 					$("#tr_" + id).remove();
			// 					layer.msg('删除成功', {icon: 1})
			// 				}
			// 			},error:function(e){
			// 				layer.msg(e.responseText, {icon: 5});
			// 			}
			// 		});
			// 	}
			//
			// });
		});
	</script>
</body>
</html>
